package com.wyg.jdbc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCUtil {
	
	public static String driver=null;
	public static String url=null;
	public static String user=null;
	public static String password=null;
	public static Connection conn=null;
	public static PreparedStatement pstmt=null;
	
	public static void getConnection(){
		try{
			Properties p = new Properties();
			InputStream is = JDBCUtil.class.getResourceAsStream("/jdbcconnect.properties");
			p.load(is);
			driver=p.getProperty("driver");
			url=p.getProperty("url");
 			user=p.getProperty("user");
			password=p.getProperty("pwd");
			
			Class.forName(driver);
			conn=DriverManager.getConnection(url, user, password);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	//查询
		public static PreparedStatement getStatmentQuery(String SQL){
			try {
				pstmt = conn.prepareStatement(SQL);			
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return pstmt;
		}
		
		public static void close(){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	

}
